/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package docview;

import java.util.Iterator;
import java.util.Vector;

/**
 *
 * @author Dema
 */
public class Vocabulary implements IObserver{
    private Vector<IObserver> observers = new Vector();
    private Vector<Selection> price = new Vector();
    private Vector<Selection> result = new Vector();

    public Vocabulary()
    {

    }

    public void add(int i) {
        
    }

    public void highlightOn(int i) {
        if (i<=price.size())
            highlight(price.get(i),Sender.PRICE);
        if (i<=result.size())
            highlight(result.get(i),Sender.RESULT);
    }

    public void highlightOff() {
       
    }

    public void highlight(Selection one, Sender _sender) {
        Iterator<IObserver> it = observers.iterator();
        while(it.hasNext())
        {
            it.next().highlight(one, _sender);
        }
    }

    public void delete(int i) {
        result.removeElementAt(i);
        price.removeElementAt(i);
    }

    public void createSelection(Selection selection, Sender sender,int i) {
        if (sender == Sender.PRICE)
        {
            if(price.size()<i)
                price.setSize(i);
            price.add(i,selection);
        }
        else
        {
            if(result.size()<i)
                result.setSize(i);
            result.add(i,selection);
        }
    }

    public void addListener(IObserver obj) {
        observers.add(obj);
    }

    public void deleteListener(IObserver obj) {
        Iterator<IObserver> it = observers.iterator();
        while(it.hasNext())
        {
            if(it.next().equals(obj))
            {
                it.remove();
                break;
            }

        }
    }
}
